class LinkedStackWithSentinel:
    """
    LIFO stack implementation using a singly sentinel linked list for storage
    """
    class _Node:
        """Singly linked node"""
        __slots__ = '_element', '_next'

        def __init__(self, element, next):
            self._element = element
            self._next = next

    def __init__(self):
        """Create an empty singly linked stack"""
        self._header = self._Node(None, None)
        self._size = 0

    def __str__(self):
        data = []
        if self._size > 0:
            walk_node: LinkedStackWithSentinel._Node = self._header._next
            while walk_node:
                data.append(walk_node._element)
                walk_node = walk_node._next
        return str(data)

    def __len__(self):
        return self._size

    def is_empty(self):
        return self._size == 0

    def top(self):
        """Return the top of statck"""
        if self.is_empty():
            raise Exception("Stack is empty")
        value = self._header._next._element
        return value

    def push(self, e):
        """Add element to the top of the stack"""
        new_node = self._Node(e, self._header._next)
        self._header._next = new_node
        self._size += 1

    def pop(self):
        """Remove and return the top of stack"""
        old_node = self._header._next
        value = old_node._element
        self._header._next = old_node._next
        old_node = None
        self._size -= 1
        return value
